<?php
namespace app\base\controller;
use think\Controller;
use think\View;
use think\Db;
class Index extends  Controller
{
    public function index()
    {
        $code = rand(1000,9999);

        $map['code'] = $code;
        $result =  sms('树人教育',$map,'SMS_71930378','18657240931');
        dump($result);


    }


    public function get_sms_code(){
        $mobile = input('param.mobile');
        $code = rand(1000,9999);
        $data = array(
            'mobile'=>$mobile,
            'code'=>$code,
            'endtime'=>time()+120,
            'type'=>'reg'
        );
        $code = (string)$code;
        $map['code'] = $code;
        $result =  sms('树人教育',$map,'SMS_71930378',$mobile);
        if($result=='发送成功'){
            $id = Db::name('user_sms_code')->insertGetId($data);
            if($id){
                return json(['code'=>1]);
            }
        }else{
            return json(['code'=>-1]);
        }



    }


    public function my_ding(){

        $id = input('param.id');
        $type = input('param.type');




        $info = Db::name($type)->field('my_ding')->where('id',$id)->find();

        if($info['my_ding']==1){

            $data['my_ding'] = 0;

            Db::name($type)->where('id',$id)->update($data);

            return json(['code' =>-1,'msg'=>'取消置顶成功']);

        }

        if($info['my_ding']==0){

            $data['my_ding'] = 1;

            Db::name($type)->where('id',$id)->update($data);

            return json(['code' =>1,'msg'=>'置顶成功']);

        }







    }


}
